@extends('admin.layout')

@section('content')
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-header layuiadmin-card-header-auto">
                @can('content.block_type.create')
                <button class="layui-btn layuiadmin-btn-com" data-type="add">添加</button>
                @endcan
            </div>
            <div class="layui-card-body">
                <table id="LAY-app-content-block_type" lay-filter="LAY-app-content-block_type"></table>
                <script type="text/html" id="table-content-options">
                    <div class="layui-btn-group">
                        @can('content.block_type.edit')
                            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                        @endcan
                        @can('content.block_type.destroy')
                                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                        @endcan
                    </div>
                </script>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script>
        layui.config({
            base: '/static/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'contlist','table'],function(){
            var $ = layui.$, table = layui.table, form = layui.form;

            //监听搜索
            form.on('submit(LAY-app-contlist-search)', function(data){
                const field = data.field;

                //执行重载
                table.reload('LAY-app-content-block_type', {
                    where: field
                });
            });

            const active = {
                add: function () {
                    layer.open({
                        type: 2
                        , title: '添加类型'
                        , content: 'block_type/create'
                        , maxmin: true
                        , area: ['450px', '300px']
                        , btn: ['确定', '取消']
                        , yes: function (index, layero) {
                            //点击确认触发 iframe 内容中的按钮提交
                            var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                            submit.click();
                        }
                    });
                }
            };
            $('.layui-btn.layuiadmin-btn-com').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
@endsection
